{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4af3adfa",
   "metadata": {},
   "source": [
    "| [01_base/06_条件判断_if.ipynb](https://github.com/shibing624/python-tutorial/blob/master/01_base/06_条件判断_if.ipynb)  | Python条件判断  |[Open In Colab](https://colab.research.google.com/github/shibing624/python-tutorial/blob/master/01_base/06_条件判断_if.ipynb) |\n",
    "\n",
    "# 条件判断\n",
    "\n",
    "### 基本用法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2e3a22dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "exam score check:\n",
      "student pass\n"
     ]
    }
   ],
   "source": [
    "a = 62\n",
    "print(\"exam score check:\")\n",
    "if a >= 60:\n",
    "    print(\"student pass\")\n",
    "elif a == 0:\n",
    "    print(\"student 0: not pass\")\n",
    "else:\n",
    "    print(\"student not pass\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fbbbc96",
   "metadata": {},
   "source": [
    "可以使用 and ， or , not 等关键词结合多个判断条件："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8faa2e35",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "a = 10\n",
    "b = -5\n",
    "print(a > 0 and b < 0)  # True\n",
    "print(not a > 0)  # False\n",
    "print(a < 0 or b < 0)  # True"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a646a33e",
   "metadata": {},
   "source": [
    "### 一个例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "92ffc111",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This is not a leap year.\n"
     ]
    }
   ],
   "source": [
    "year = 1900\n",
    "if year % 400 == 0:\n",
    "    print(\"This is a leap year!\")\n",
    "# 两个条件都满足才执行\n",
    "elif year % 4 == 0 and year % 100 != 0:\n",
    "    print(\"This is a leap year!\")\n",
    "else:\n",
    "    print(\"This is not a leap year.\")\n",
    "# This is not a leap year."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "feaffbfc",
   "metadata": {},
   "source": [
    "### 判断列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ccc00f7a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the first element is:  1\n"
     ]
    }
   ],
   "source": [
    "my_list = [1, 2]\n",
    "# 判断一个列表是否为空。\n",
    "if len(my_list) > 0:\n",
    "    print(\"the first element is: \", my_list[0])\n",
    "else:\n",
    "    print(\"no element.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c6f77b2",
   "metadata": {},
   "source": [
    "本节完。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}